//
//  XWXShareHelper.m
//  ShareMorePicToWX
//
//  Created by Dylan Chen on 2017/5/26.
//  Copyright © 2017年 Dylan. All rights reserved.
//

#import "XWXShareHelper.h"
#import <Social/Social.h>

@interface XWXShareHelper()


@end

@implementation XWXShareHelper

static XWXShareHelper *shareHelper;

#pragma mark - 单例
+ (instancetype)shareHelper{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        shareHelper = [[XWXShareHelper alloc] init];
    });
    return shareHelper;
}

#pragma mark - Public
+ (void)shareWithController:(UIViewController *)controller
     andItems:(NSArray *)items
andCompletion:(XWXShareHelperCompleteHandler)completion
{
    __block BOOL success = YES;
    UIActivityViewController *vc = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
    // 拒绝分享到的位置，根据需求筛选
    if (@available(iOS 11.0, *)) {
        vc.excludedActivityTypes = @[UIActivityTypePostToFacebook,UIActivityTypePostToTwitter,UIActivityTypePostToWeibo,UIActivityTypeMessage,UIActivityTypeMail,UIActivityTypePrint,UIActivityTypeCopyToPasteboard,UIActivityTypeAssignToContact,UIActivityTypeAddToReadingList,UIActivityTypePostToFlickr,UIActivityTypePostToVimeo,UIActivityTypeAirDrop,UIActivityTypeOpenInIBooks,UIActivityTypeMarkupAsPDF];
    } else {
        // Fallback on earlier versions
    }
    [controller presentViewController:vc animated:YES completion:nil];
    vc.completionWithItemsHandler = ^(UIActivityType  _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) {
        if (completed) {
            // 分享成功！
            success = YES;
        } else {
            // 分享失败！
            success = NO;
        }
        completion(success);
    };
}


/**
#pragma mark - Private
- (NSString *)serviceTypeWithType:(XWXShareHelperShareType)type
{
    // 这个方法不再进行校验,传入就不等于0.这里做一个转换
    NSString * serviceType;
    if (type != 0) {
        switch (type){
            case TSShareHelperShareTypeWeChat:
                //com.tencent.xin.sharetimeline
                serviceType = @"com.tencent.xin.sharetimeline";
                break;
            case TSShareHelperShareTypeQQ:
                serviceType = @"com.tencent.mqq.ShareExtension";
                break;
            case TSShareHelperShareTypeSina:
                if(@available(iOS 11.0, *))
                {
                   serviceType = SLServiceTypeSinaWeibo;
//                    NSLog(@"%@",SLServiceTypeSinaWeibo);
                }else {
                    //com.apple.share.SinaWeibo.post
                    serviceType = @"com.apple.share.SinaWeibo.post";
                }
                
                break;
            default:
                break;
        }
    }
    return serviceType;
}

*/

@end
